package org.create.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class JsonUtils {
    public static String toJson(Object obj) {
        if (obj == null) {
            return null;
        }
        // 第二个参数避免循环引用，导致无限递归
        return JSON.toJSONString(obj, SerializerFeature.DisableCircularReferenceDetect);
    }

    public static <T> T toObject(String str, Class<T> tClass) {
        DataTool.checkStr(str);
        return JSON.parseObject(str, tClass);
    }
}
